/* @(#)FmmNodeAuditImpl.java
** 
** Copyright (C) 2012 by Steven D. Stamps
**
**             Trademarks & Copyrights
** Flywheel Management Science(TM), Flywheel Management Model(TM),
** Flywheel Story Editor(TM) and FlywheelMS(TM) are exclusive trademarks
** of Steven D. Stamps and may only be used freely for the purpose of
** identifying the unforked version of this software.  Subsequent forks
** may not use these trademarks.  All other rights are reserved.
**
** DecKanGL (Decorated Kanban Glyph Language) and TribKn (Tribal Knowledge)
** are also exclusive trademarks of Steven D. Stamps.  These may be used
** freely within the unforked FlywheelMS application and documentation.
** All other rights are reserved.
**
** gConGUI (game Controller Graphical User Interface) is an exclusive
** trademark of Steven D. Stamps.  This trademark may be used freely
** within the unforked FlywheelMS application and documentation.
** All other rights are reserved.
**
** Trademark information is available at
** <http://www.flywheelms.com/trademarks>
**
** Flywheel Management Science(TM) is a copyrighted body of management
** metaphors, governance processes, and leadership techniques that is
** owned by Steven D. Stamps.  These copyrighted materials may be freely
** used, without alteration, by the community (users and developers)
** surrounding this GPL3-licensed software.  Additional copyright
** information is available at <http://www.flywheelms.org/copyrights>
**
**              GPL3 Software License
** This program is free software: you can use it, redistribute it and/or
** modify it under the terms of the GNU General Public License, version 3,
** as published by the Free Software Foundation. This program is distributed
** in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
** even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
** PURPOSE.  See the GNU General Public License for more details. You should
** have received a copy of the GNU General Public License, in a file named
** COPYING, along with this program.  If you cannot find your copy, see
** <http://www.gnu.org/licenses/gpl-3.0.html>.
*/

package com.flywheelms.library.fmm.node.impl.audit;

import java.util.Date;

import com.flywheelms.library.fca.FlywheelCommunityAuthentication;
import com.flywheelms.library.fmm.node.NodeId;
import com.flywheelms.library.fmm.node.impl.FmmNodeImpl;
import com.flywheelms.library.fmm.node.impl.nodefrag.NodeFragAuditBlock;
import com.flywheelms.library.fmm.node.interfaces.horizontal.FmmNodeAudit;

public abstract class FmmNodeAuditImpl extends FmmNodeImpl implements FmmNodeAudit {
	
	private NodeFragAuditBlock auditBlock; 

	public FmmNodeAuditImpl(NodeId aNodeId) {
		super(aNodeId);
		this.auditBlock = new NodeFragAuditBlock(aNodeId.getNodeIdString());
	}
	
	@Override
	public NodeFragAuditBlock getAuditBlock() {
		return this.auditBlock;
	}

	@Override
	public void setAuditBlock(NodeFragAuditBlock anAuditBlock) {
		this.auditBlock = anAuditBlock;
	}
	
	//  Created  //
	
	@Override
	public NodeId getCreatedBy() {
		return this.auditBlock.getCreatedBy();
	}
	
	@Override
	public String getCreatedByNodeIdString() {
		return this.auditBlock.getCreatedBy().getNodeIdString();
	}

	@Override
	public void setCreatedBy(NodeId aNodeId) {
		this.auditBlock.setCreatedBy(aNodeId);
	}
	
	@Override
	public void setCreatedBy(String aNodeIdString) {
		this.auditBlock.setCreatedBy(aNodeIdString);
	}

	@Override
	public Date getCreatedTimestamp() {
		return this.auditBlock.getCreatedTimestamp();
	}
	
	@Override
	public void setCreatedTimestamp(Date aCreatedTimestamp) {
		this.auditBlock.setCreatedTimestamp(aCreatedTimestamp);
	}
	
	//  Updated  //

	@Override
	public NodeId getLastUpdatedBy() {
		return this.auditBlock.getLastUpdatedBy();
	}

	@Override
	public String getLastUpdatedByNodeIdString() {
		return this.auditBlock.getLastUpdatedBy().getNodeIdString();
	}

	@Override
	public void setLastUpdatedBy(NodeId aNodeId) {
		this.auditBlock.setLastUpdatedBy(aNodeId);
	}

	@Override
	public void setLastUpdatedBy(String aNodeIdString) {
		this.auditBlock.setLastUpdatedBy(aNodeIdString);
	}

	@Override
	public Date getLastUpdatedTimestamp() {
		return this.auditBlock.getLastUpdatedTimestamp();
	}

	@Override
	public void setLastUpdatedTimestamp(Date aLastUpdate) {
		this.auditBlock.setLastUpdatedTimestamp(aLastUpdate);
	}
	
	//  Locked  //

	@Override
	public NodeId getLockedBy() {
		return this.auditBlock.getLockedBy();
	}

	@Override
	public String getLockedByNodeIdString() {
		return this.auditBlock.getLockedBy().getNodeIdString();
	}

	@Override
	public void setLockedBy(NodeId aNodeId) {
		this.auditBlock.setLockedBy(aNodeId);
	}
	
	@Override
	public void setLockedBy(String aNodeIdString) {
		this.auditBlock.setLockedBy(aNodeIdString);
	}

	@Override
	public Date getLockedTimestamp() {
		return this.auditBlock.getLockedTimestamp();
	}
	
	@Override
	public void setLockedTimestamp(Date aLockedTimestamp) {
		this.auditBlock.setLockedTimestamp(aLockedTimestamp);
	}

	@Override
	public void lock() {
		this.auditBlock.setLockedBy(FlywheelCommunityAuthentication.getInstance().getFcaUserCredentials().getFcaUserId());
		this.auditBlock.setLockedTimestamp(new Date());
		this.auditBlock.setLocked(true);
	}

	@Override
	public void unlock() {
		// we want to know who unlocked it, and when
		this.auditBlock.setLockedBy(FlywheelCommunityAuthentication.getInstance().getFcaUserCredentials().getFcaUserId());
		this.auditBlock.setLockedTimestamp(new Date());
		this.auditBlock.setLocked(false);
	}
	
	@Override
	public void setLocked(boolean isLocked) {
		this.auditBlock.setLocked(isLocked);
	}

	@Override
	public boolean isLocked() {
		return this.auditBlock.isLocked();
	}
	
}
